**This do-file extracts election dates from Manifesto Project

use "$project_path/data/1_input/elections/MP/MPDataset_MPDS2018a_stata14.dta", clear

// Keeping one observation per election
keep countryname edate 
ren countryname Country
duplicates drop

// Creating month and year variables
gen Month = month(edate)
gen Year = year(edate)
bys Country Year: gen temp = _N
replace Month = . if temp==1
drop temp 
ren edate Date

// Adjusting country names
replace Country="Bosnia-Herz"  if Country=="Bosnia-Herzegovina"
replace Country="Czech Rep."  if Country=="Czech Republic"
replace Country="GDR"  if Country=="German Democratic Republic"
replace Country="FRG/Germany"  if Country=="Germany"
replace Country="S. Africa"  if Country=="South Africa"
replace Country="Korea, Republic of"  if Country=="South Korea"
replace Country="UK"  if Country=="United Kingdom"
replace Country="USA"  if Country=="United States"

// Adjusting month variable
replace Month = 11 if Country=="France" & Year==1946
replace Month = 7 if Country=="Moldova" & Year==2009
replace Month = 7 if Country=="Sri Lanka" & Year==1960
replace Month = 4 if Country=="Iceland" & Year==1991
replace Month = 12 if Country=="Serbia" & Year==1992

gen Type_Election="Parliamentary"

keep if Year>1945

sort Type_Election Country Year Month Date
order Country Year Month Type_Election Date
format Country %20s
notes drop _dta
compress

save "$project_path/data/2_intermediary/elections/Election dates/dates_mp.dta", replace
